#!/bin/bash
PORT_CONSUMER=1028
PORT_PROVIDER=2028
PORT_PROVIDER_GAME=3028
PORT_PROVIDER_LOG=4028
PORT_XXL=9010

PID_CONSUMER=`netstat -anp|grep $PORT_CONSUMER|awk '{printf $7}'|cut -d/ -f1 `
PID_PROVIDER=`netstat -anp|grep $PORT_PROVIDER|awk '{printf $7}'|cut -d/ -f1 `
PID_PROVIDER_GAME=`netstat -anp|grep $PORT_PROVIDER_GAME|awk '{printf $7}'|cut -d/ -f1 `
PID_PROVIDER_LOG=`netstat -anp|grep $PORT_PROVIDER_LOG|awk '{printf $7}'|cut -d/ -f1 `
PID_XXL=`netstat -anp|grep $PORT_XXL|awk '{printf $7}'|cut -d/ -f1 `




stop_consumer(){
  if [ $? -eq "0" ]; then
      for id in $PID_CONSUMER
      do
        kill -9 $id
      done
  else
    echo "${PORT_CONSUMER} is not running"
  fi
}

stop_provider(){
  if [ $? -eq "0" ]; then
      for id in $PID_PROVIDER
      do
        kill -9 $id
      done
  else
    echo "${PORT_PROVIDER} is not running"
  fi
}

stop_provider_game(){
  if [ $? -eq "0" ]; then
      for id in $PID_PROVIDER_GAME
      do
        kill -9 $id
      done
  else
    echo "${PORT_PROVIDER_GAME} is not running"
  fi
}

stop_xxl(){
  if [ $? -eq "0" ]; then
      for id in $PID_XXL
      do
        kill -9 $id
      done
  else
    echo "${PORT_XXL} is not running"
  fi
}

stop_provider_log(){
  if [ $? -eq "0" ]; then
      for id in $PID_PROVIDER_LOG
      do
        kill -9 $id
      done
  else
    echo "${PID_PROVIDER_LOG} is not running"
  fi
}

isExist(){
  if [ -z "${PID}" ]; then
      return 1
    else
      return 0
  fi
}


stop(){
  stop_consumer
  stop_xxl
  stop_provider_game
  stop_provider_log
  stop_provider
}

stop